package com.jinsilu.freight.ui.adapter;

import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.jinsilu.freight.R;
import com.jinsilu.freight.helper.CommonHelper;
import com.jinsilu.freight.http.response.WaybillBean;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class UnfinishedWaybillAdapter extends BaseQuickAdapter<WaybillBean, BaseViewHolder> {

    public UnfinishedWaybillAdapter(@Nullable List<WaybillBean> data) {
        super(R.layout.item_waybill, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, WaybillBean bean) {
        holder.setText(R.id.item_waybill_company_name, bean.getPartnerName())
                .setText(R.id.item_waybill_no, String.format("运单号：%s", bean.getWaybillNumber()))
                .setText(R.id.item_waybill_address, String.format("%s", bean.getLineName()))
                .setText(R.id.item_waybill_goods_name, bean.getGoodsName())
                .setText(R.id.item_waybill_money_name, String.format("%s元/吨", bean.getSettlePrice()))
                .setText(R.id.item_waybill_load_number, String.format("%s吨", TextUtils.isEmpty(bean.getUploadWeight()) ? "0.00" : bean.getUploadWeight()))
                .setText(R.id.item_waybill_unloading_number, String.format("%s吨", TextUtils.isEmpty(bean.getUnloadWeight()) ? "0.00" : bean.getUnloadWeight()))
                .setText(R.id.item_waybill_allow_loss, String.format("允许亏吨：%s吨", bean.getLossWeight()))
                .setText(R.id.item_waybill_grab_date, String.format("抢单时间：%s", bean.getGrabTime()))
                .setText(R.id.item_phone, String.format("司机手机：%s", bean.getDriverPhone()))
                .setText(R.id.item_vehicle_number, String.format("车牌号：%s", bean.getVehicleNumber()))
                .setText(R.id.item_driver_name, String.format("司机姓名：%s", bean.getDriverName()));
//                .setText(R.id.item_waybill_remark, String.format("备注：%s", TextUtils.isEmpty(bean.getRemarks()) ? "无" :
//                        TextUtils.isEmpty(bean.getRemarks().trim()) ? "无" : bean.getRemarks()));

        if (1 == bean.getWaybillStatus()) {
            holder.setGone(R.id.iv_view_loading_image, true)
                    .setGone(R.id.iv_view_unloading_image, true);
        }

        // 0 白条未开通 2 运单状态未卸车 显示开通白条支付
//        holder.setGone(R.id.tv_open_the_blank_note, 0 != bean.getApplyWhite() || 2 != bean.getWaybillStatus() && !CommonHelper.isShowBlankNote());

        // 3  已卸车  4  装车打回  5  卸车打回  6  装卸车打回
        /**
         * upadate 2021年02月24日 14:35:42 @ly
         * 1:待装货(抢完单)     显示上传卸车磅单
         * 2:运输中(上传装车磅单后)显示上传卸车磅单
         * 3:已卸车(上传卸车磅单后)   显示结算中
         * 4:装车磅单打回    显示装车磅单打回
         * 5:卸车磅单打回  卸车磅单打回
         * 6:装卸车打回   装卸车打回 上传装车后显示上传卸车，都上传完后
         * 7:支付中     显示结算中
         * 后面都是已完成
         * 8:已支付 9:开票中 10:已开票
         */
        switch (bean.getWaybillStatus()) {
            case 1:
                holder.setText(R.id.item_waybill_status_one, "未装车")
                        .setBackgroundResource(R.id.item_waybill_status_one, R.drawable.waybill_red_bg_ic)
                        .setText(R.id.item_waybill_upload_unloading, "上传装车磅单")
                        .setGone(R.id.item_waybill_upload_unloading, false)
                        .setText(R.id.item_waybill_more, "删除")
                        .setGone(R.id.item_waybill_more, false);
                // 隐藏装卸图片
                holder.setGone(R.id.iv_view_loading_image, true)
                        .setGone(R.id.iv_view_unloading_image, true);
                break;
            case 2:
                holder.setText(R.id.item_waybill_status_one, "运输中")
                        .setBackgroundResource(R.id.item_waybill_status_one, R.drawable.waybill_orange_bg_ic)
                        .setText(R.id.item_waybill_upload_unloading, "上传卸车磅单")
                        .setGone(R.id.item_waybill_upload_unloading, false)
                        .setGone(R.id.item_waybill_more, true);
                // 显示装车磅单
                holder.setGone(R.id.iv_view_loading_image, false)
                        .setGone(R.id.iv_view_unloading_image, true);

                break;
            case 3:
            case 7:
                holder.setText(R.id.item_waybill_status_one, "结算中")
                        .setBackgroundResource(R.id.item_waybill_status_one, R.drawable.waybill_green_bg_ic)
                        .setText(R.id.item_waybill_upload_unloading, "")
                        .setGone(R.id.item_waybill_upload_unloading, true);

                // 显示装/卸车磅单
                holder.setGone(R.id.iv_view_loading_image, false)
                        .setGone(R.id.iv_view_unloading_image, false);
                break;
            case 4: // 装车打回
                holder.setText(R.id.item_waybill_status_one, "装车打回")
                        .setBackgroundResource(R.id.item_waybill_status_one, R.drawable.waybill_red_bg_ic)
                        .setText(R.id.item_waybill_upload_unloading, "上传装车磅单")
                        .setGone(R.id.item_waybill_upload_unloading, false)
                        .setGone(R.id.item_waybill_more, true);
                // 隐藏装卸图片
                holder.setGone(R.id.iv_view_loading_image, false)
                        .setGone(R.id.iv_view_unloading_image, true);
                break;
            case 5:
                holder.setText(R.id.item_waybill_status_one, "卸车打回")
                        .setBackgroundResource(R.id.item_waybill_status_one, R.drawable.waybill_red_bg_ic)
                        .setText(R.id.item_waybill_upload_unloading, "上传卸车磅单")
                        .setGone(R.id.item_waybill_upload_unloading, false)
                        .setGone(R.id.item_waybill_more, true);
                // 隐藏装卸图片
                holder.setGone(R.id.iv_view_loading_image, false)
                        .setGone(R.id.iv_view_unloading_image, false);
                break;
            case 6:
                holder.setText(R.id.item_waybill_status_one, "装卸车打回")
                        .setBackgroundResource(R.id.item_waybill_status_one, R.drawable.waybill_red_bg_ic)
                        .setText(R.id.item_waybill_upload_unloading, "上传装车磅单")
                        .setGone(R.id.item_waybill_upload_unloading, false)
                        .setGone(R.id.item_waybill_more, true);
                // 隐藏装卸图片
                holder.setGone(R.id.iv_view_loading_image, false)
                        .setGone(R.id.iv_view_unloading_image, false);
                break;
        }
    }
}
